package es.deusto.ingenieria.is.Hanoi.formulation;


import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.GregorianCalendar;

import es.deusto.ingenieria.is.Hanoi.heuristics.Heuristic1;
import es.deusto.ingenieria.is.Hanoi.heuristics.Heuristic2;
import es.deusto.ingenieria.is.Hanoi.heuristics.Heuristic3;
import es.deusto.ingenieria.is.search.NewHillClimbing;
import es.deusto.ingenieria.is.search.algorithms.*;
import es.deusto.ingenieria.is.search.algorithms.blind.BreadthFS;
import es.deusto.ingenieria.is.search.algorithms.blind.BreadthFSwithLog;
import es.deusto.ingenieria.is.search.algorithms.blind.DepthFS;
import es.deusto.ingenieria.is.search.algorithms.blind.DepthFSwithLog;
import es.deusto.ingenieria.is.search.algorithms.heuristic.BestFS;
import es.deusto.ingenieria.is.search.algorithms.heuristic.BestFSwithLog;
import es.deusto.ingenieria.is.search.algorithms.heuristic.EvaluationFunction;





public class MainProgram {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		try {
			SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss.S");
			Date beginDate = GregorianCalendar.getInstance().getTime();
			System.out.println("\n* Start '" + "' (" + formatter.format(beginDate) + ")");				
			
			//6 discos - 3 soportes
			Problema_Hanoi problem = new Problema_Hanoi(6, 3, 1, 3);
			//Estado_Hanoi s = (Estado_Hanoi) problem1.getInitialStates().get(0);
			
			//6 discos - 4 soportes
			//Problema_Hanoi problem = new Problema_Hanoi(6, 4, 1, 3);
			/*Estado_Hanoi s = (Estado_Hanoi) problem.getInitialStates().get(0);
			
			Heuristic1 h1 = new Heuristic1(s);
			Heuristic2 h2 = new Heuristic2(s);
			Heuristic3 h3 = new Heuristic3(s);
			BestFS bfs1 = new BestFS(h1);
			BestFS bfs2 = new BestFS(h2);  
			BestFS bfs3 = new BestFS(h3);  
			System.out.println(bfs3.search(problem, s).toString());	*/	
			Estado_Hanoi s = (Estado_Hanoi) problem.getInitialStates().get(0);
			
			//Heuristic1 h1 = new Heuristic1(s);
			Heuristic2 h2 = new Heuristic2(s);
			NewHillClimbing hc=new NewHillClimbing(h2);
			//SearchMethod search = BreadthFSwithLog.getInstance();
			//SearchMethod search = DepthFSwithLog.getInstance();
			//SearchMethod search = BreadthFS.getInstance();
			SearchMethod search = hc;
			problem.solve(search);
			
			Date endDate = GregorianCalendar.getInstance().getTime();		
			System.out.println("* End   '" + "' (" + formatter.format(endDate) + ")");
			long miliseconds = (int) Math.abs(beginDate.getTime() - endDate.getTime());
			long seconds = miliseconds / 1000;
			miliseconds %= 1000;		
			long minutes = seconds / 60;
			seconds %= 60;
			long hours = minutes / 60;
			minutes %= 60;
			String time = "\n* Search lasts: ";
			time += (hours > 0) ? hours + " h " : " ";
			time += (minutes > 0) ? minutes + " m " : " ";
			time += (seconds > 0) ? seconds + "s " : " ";
			time += (miliseconds > 0) ? miliseconds + "ms " : " ";
			
			System.out.println(time);

		} catch (Exception ex) {
			System.err.println("% [MainProgram] Error: " + ex.getMessage());
			ex.printStackTrace();
		}
	}

}
